package com.wwwarehouse.contract.program_operation;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.eventbus_event.BackListenerEvent;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.DialogTools;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.contract.adapter.PinCardAdapter;
import com.wwwarehouse.contract.bean.ChooseModuleBean;
import com.wwwarehouse.contract.bean.CustomerAndResBean;
import com.wwwarehouse.contract.bean.CustomerAndResListBean;
import com.wwwarehouse.contract.bean.SaveModulesBean;
import com.wwwarehouse.contract.bean.SaveModulesValue;
import com.wwwarehouse.contract.bean.SourceListBean;
import com.wwwarehouse.contract.bean.TestBean;
import com.wwwarehouse.contract.core.ContractConstant;
import com.wwwarehouse.contract.event.CheckAllResFactorEvent;
import com.wwwarehouse.contract.event.CheckCustomersEvent;
import com.wwwarehouse.contract.event.CheckIndusEvent;
import com.wwwarehouse.contract.event.CheckResEvent;
import com.wwwarehouse.contract.event.CheckResourceFactorShipEvent;
import com.wwwarehouse.contract.event.CheckResourceShipEvent;
import com.wwwarehouse.contract.event.CheckSupplyEvent;
import com.wwwarehouse.contract.program_operation.resource_factor_ship.ResourceFactorShipViewPagerFragment;
import com.wwwarehouse.contract.program_operation.resource_ship.ResourceShipViewPagerFragment;
import com.wwwarehouse.contract.program_operation.resources_factor_page.ResourceFactorMainFragment;
import com.wwwarehouse.contract.program_operation.resources_page.SupplyOfResourceViewPagerFragment;
import com.wwwarehouse.contract.program_operation.select_industry.SelectIndustryViewPagerFragment;
import com.wwwarehouse.contract.request.ModuleQueryRequest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

/**
 * Created by feng.gao on 2017/9/21.
 * 任务卡入口进来的 拼卡主页
 */
@Route(path = "/contract/isFunctionPinCardMainFragment")
public class isFunctionPinCardMainFragment extends BaseFragment implements View.OnClickListener, AdapterView.OnItemClickListener {
    private LinearLayout mIndusLayout; //顶部行业布局
    private LinearLayout mResourceShipLayout; //底部资源关系
    private LinearLayout mResourceFactorShipLayout; //底部资源要素关系按钮
    private MyListView mClientLv, mResourceLv, mResourceFactorLv, mSupplierLv;   //客户 、 资源、资源要素、供应商 4个竖直拼卡
    private TextView mIndustryTv; //行业文本
	private TextView mCardTv;
	private PinCardAdapter mClientAdapter, mResourceAdapter, mResourceFactorAdapter, mSupplierAdapter;
    private ImageView mResourceShipIv , mResourceFactorShipIv;
    private TextView mResourceShipTv , mResourceFactorShipTv;
    //4个listView的实体数据
    private List<ChooseModuleBean.ModuleList.BeanList> mClientPinCardBeanList = new ArrayList<>();
    private List<ChooseModuleBean.ModuleList.BeanList> mResourcePinCardBeanList = new ArrayList<>();
    private List<ChooseModuleBean.ModuleList.BeanList> mResourceFactorPinCardBeanList = new ArrayList<>();
    private List<ChooseModuleBean.ModuleList.BeanList> mSupplierPinCardBeanList = new ArrayList<>();

    private List<ChooseModuleBean.ModuleList.BeanList> mIndustryCheckedList = new ArrayList<>(); //行业已选的条目
    private List<ChooseModuleBean.ModuleList.BeanList> mDefaultIndustryCheckedList = new ArrayList<>(); //行业默认选择的条目

    private List<ChooseModuleBean.ModuleList.BeanList> mCustomerCheckedList = new ArrayList<>(); //客户已选的条目
    private List<ChooseModuleBean.ModuleList.BeanList> mResourceCheckedList = new ArrayList<>(); //资源已选的条目
    private List<ChooseModuleBean.ModuleList.BeanList> mNeedResourceFactorCheckedList = new ArrayList<>(); //需要的资源要素已选的条目
    private List<ChooseModuleBean.ModuleList.BeanList> mHaveResourceFactorCheckedList = new ArrayList<>(); //拥有的资源要素已选的条目
    private List<ChooseModuleBean.ModuleList.BeanList> mCustomersAndResourceListFromNet = new ArrayList<>(); //
    private List<ChooseModuleBean.ModuleList.BeanList> mResourceFactorAndSupplyListFromNet = new ArrayList<>(); //

    private List<ChooseModuleBean.ModuleList.BeanList> mSupplierCheckedList = new ArrayList<>(); //供应商已选的条目
    int mLvHeight;
    CustomerAndResBean mCustomerAndResBean;

    CustomerAndResBean mRecourseFactorShipBean;
    CustomerAndResBean mYuanShuJu;

    ElasticScrollView mElasticScrollView;
    private StateLayout mStateLayout = null;

    Button titleBt1;
    private boolean isEdited;
    boolean isShow;
    private String mBusId;
    private String mCardUkid;
    @Override
    public void setTitle() {
        if (peekFragment() instanceof isFunctionPinCardMainFragment) {
            mActivity.setTitle(R.string.programming_operation_title);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.pincard_main_layout, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (getArguments() != null && getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS) != null) {
            CardDeskFunctionResponseBean.TaskBean taskBean = (CardDeskFunctionResponseBean.TaskBean) getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
            if (taskBean != null && taskBean.getBusinessId() != null && taskBean.getTaskTypeUkid() != null ) {
                mBusId = taskBean.getBusinessId();
                mCardUkid = taskBean.getTaskTypeUkid();
            }
        }
        initView(view);
        initEvent();
    }

    /**
     * 返回参数List
     *
     * @return
     */
    private List<SourceListBean> getSourceList(String type) {
        List<SourceListBean> mAllList = new ArrayList<>();
        if (mIndustryCheckedList != null && mIndustryCheckedList.size() > 0 && !type.equals("INDUSTRY")) {
            traverseList(mAllList, mIndustryCheckedList, "INDUSTRY");
        } else if (mDefaultIndustryCheckedList != null && mDefaultIndustryCheckedList.size() > 0 && !type.equals("INDUSTRY")) {
            traverseList(mAllList, mDefaultIndustryCheckedList, "INDUSTRY");
        }
        if (mCustomerCheckedList != null && mCustomerCheckedList.size() > 0 && !type.equals("CUSTOMER")) {
            traverseList(mAllList, mCustomerCheckedList, "CUSTOMER");
        }
        if (mResourceCheckedList != null && mResourceCheckedList.size() > 0 && !type.equals("RESOURCE")) {
            traverseList(mAllList, mResourceCheckedList, "RESOURCE");
        }
        if (mHaveResourceFactorCheckedList != null && mHaveResourceFactorCheckedList.size() > 0 && !type.equals("HAVE_RESOURCE_FACTORS")) {
            traverseList(mAllList, mHaveResourceFactorCheckedList, "HAVE_RESOURCE_FACTORS");
        }
        if (mNeedResourceFactorCheckedList != null && mNeedResourceFactorCheckedList.size() > 0 && !type.equals("NEED_RESOURCE_FACTORS")) {
            traverseList(mAllList, mNeedResourceFactorCheckedList, "NEED_RESOURCE_FACTORS");
        }
        if (mSupplierCheckedList != null && mSupplierCheckedList.size() > 0 && !type.equals("PROVIDER")) {
            traverseList(mAllList, mSupplierCheckedList, "PROVIDER");
        }
        return mAllList;


    }

    //遍历List
    private List<SourceListBean> traverseList(List<SourceListBean> list, List<ChooseModuleBean.ModuleList.BeanList> beanLists, String type) {
        if (beanLists.size() > 0) {
            for (int i = 0; i < beanLists.size(); i++) {
                SourceListBean sourceListBean = new SourceListBean();
                sourceListBean.setCode(beanLists.get(i).getCode());
                sourceListBean.setModule(type);
                list.add(sourceListBean);
            }
        }
        return list;
    }

    @Override
    public void titleBt1Click() {
	    if (peekFragment() instanceof isFunctionPinCardMainFragment) {
            if (mCustomerAndResBean == null && mRecourseFactorShipBean == null ) {
                ToastUtils.showToast("没有选择提供服务关系或采购资源关系，无法完成！");
                if (isShow) {
                    ((BaseCardDeskActivity) mActivity).hideTitleBt();
                }
                isShow = !isShow;
                return;
            }
        showProgressDialog("正在请求数据...");
        Map<String, Object> paramsMap = new HashMap<>();
        if (mBusId != null) {
            paramsMap.put("buId", mBusId);
        }
        paramsMap.put("cardUkid", null );
        paramsMap.put("taskType", "function");

        if (mCustomerAndResBean != null) {
            CustomerAndResBean customerAndResBean = new CustomerAndResBean();
            customerAndResBean.setListBeen(mCustomerAndResBean.getListBeen());

            for (int i = customerAndResBean.getListBeen().size()-1; i >= 0; i--) {
                for (int j = customerAndResBean.getListBeen().get(i).getList().size() - 1; j >= 0; j--) {
                    if (!customerAndResBean.getListBeen().get(i).getList().get(j).isSelected()) {
                        customerAndResBean.getListBeen().get(i).getList().remove(j);
                    }

                }

            }

            for (int i = customerAndResBean.getListBeen().size() - 1 ; i >= 0; i--) {
                if (customerAndResBean.getListBeen().get(i).getList().size() == 0) {
                    customerAndResBean.getListBeen().remove(i);
                }
            }
            Map<String, List<String>> map = new HashMap<>();
            for (int i = 0; i < customerAndResBean.getListBeen().size(); i++) {
                List<String> list = new ArrayList<String>();
                for (int j = 0; j < customerAndResBean.getListBeen().get(i).getList().size(); j++) {
                    list.add(customerAndResBean.getListBeen().get(i).getList().get(j).getCode());
                    map.put(customerAndResBean.getListBeen().get(i).getCode(), list);
                }
            }
            //拿到过滤之后的数据 ，里面只有关联过的数据
            List<SaveModulesValue> customerAndResourceParam = new ArrayList<SaveModulesValue>();
            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(entry.getKey());
                saveModulesValue.setValue(listToString(entry.getValue()));
                customerAndResourceParam.add(saveModulesValue);
            }

            //资源关系参数
            paramsMap.put("customerAndResourceMap", customerAndResourceParam);

        }
        if (mCustomerCheckedList != null && mCustomerCheckedList.size() > 0) {
            List<SaveModulesValue> customerParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mCustomerCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mCustomerCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mCustomerCheckedList.get(i).getProgress()));
                customerParams.add(saveModulesValue);
            }
            paramsMap.put("customerMap", customerParams);

        }

        if (mHaveResourceFactorCheckedList != null && mHaveResourceFactorCheckedList.size() > 0) {
            List<SaveModulesValue> haveResourceFactorParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mHaveResourceFactorCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mHaveResourceFactorCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mHaveResourceFactorCheckedList.get(i).getProgress()));
                haveResourceFactorParams.add(saveModulesValue);
            }
            paramsMap.put("haveResourceFactorsMap", haveResourceFactorParams);

        }
        if (mIndustryCheckedList != null && mIndustryCheckedList.size() > 0) {
            List<SaveModulesValue> industryParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mIndustryCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mIndustryCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mIndustryCheckedList.get(i).getProgress()));
                industryParams.add(saveModulesValue);
            }
            paramsMap.put("industryMap", industryParams);
        } else if (mDefaultIndustryCheckedList != null && mDefaultIndustryCheckedList.size() > 0) {
            List<SaveModulesValue> industryParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mDefaultIndustryCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mDefaultIndustryCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mDefaultIndustryCheckedList.get(i).getProgress()));
                industryParams.add(saveModulesValue);
            }
            paramsMap.put("industryMap", industryParams);
        }

        if (mNeedResourceFactorCheckedList != null && mNeedResourceFactorCheckedList.size() > 0) {
            List<SaveModulesValue> needResourceFactorParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mNeedResourceFactorCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mNeedResourceFactorCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mNeedResourceFactorCheckedList.get(i).getProgress()));
                needResourceFactorParams.add(saveModulesValue);
            }
            paramsMap.put("needResourceFactorsMap", needResourceFactorParams);
        }
/**
 * 资源关系 ===============================================================================================
 */
        if (mRecourseFactorShipBean != null) {
            CustomerAndResBean customerAndResBean = new CustomerAndResBean();
            customerAndResBean.setListBeen(mRecourseFactorShipBean.getListBeen());

            for (int i = customerAndResBean.getListBeen().size()-1; i >= 0; i--) {
                for (int j = customerAndResBean.getListBeen().get(i).getList().size() - 1; j >= 0; j--) {
                    if (!customerAndResBean.getListBeen().get(i).getList().get(j).isSelected()) {
                        customerAndResBean.getListBeen().get(i).getList().remove(j);
                    }

                }

            }

            for (int i = customerAndResBean.getListBeen().size() - 1 ; i >= 0; i--) {
                if (customerAndResBean.getListBeen().get(i).getList().size() == 0) {
                    customerAndResBean.getListBeen().remove(i);
                }
            }
            Map<String, List<String>> map = new HashMap<>();
            for (int i = 0; i < customerAndResBean.getListBeen().size(); i++) {
                List<String> list = new ArrayList<String>();
                for (int j = 0; j < customerAndResBean.getListBeen().get(i).getList().size(); j++) {
                    list.add(customerAndResBean.getListBeen().get(i).getList().get(j).getCode());
                    map.put(customerAndResBean.getListBeen().get(i).getCode(), list);
                }
            }
            //拿到过滤之后的数据 ，里面只有关联过的数据
            List<SaveModulesValue> customerAndResourceParam = new ArrayList<SaveModulesValue>();
            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(entry.getKey());
                saveModulesValue.setValue(listToString(entry.getValue()));
                customerAndResourceParam.add(saveModulesValue);
            }

            //资源关系参数
            paramsMap.put("providerAndResourceFactorsMap", customerAndResourceParam);

        }
        /**
         * 资源关系结束 ===============================================================================================
         */
        if (mSupplierCheckedList != null && mSupplierCheckedList.size() > 0) {
            List<SaveModulesValue> supplierCheckParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mSupplierCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mSupplierCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mSupplierCheckedList.get(i).getProgress()));
                supplierCheckParams.add(saveModulesValue);
            }
            paramsMap.put("providerMap", supplierCheckParams);
        }

        if (mResourceCheckedList != null && mResourceCheckedList.size() > 0) {
            List<SaveModulesValue> resourceCheckParams = new ArrayList<SaveModulesValue>();
            for (int i = 0; i < mResourceCheckedList.size(); i++) {
                SaveModulesValue saveModulesValue = new SaveModulesValue();
                saveModulesValue.setCode(mResourceCheckedList.get(i).getCode());
                saveModulesValue.setValue(String.valueOf(mResourceCheckedList.get(i).getProgress()));
                resourceCheckParams.add(saveModulesValue);
            }
            paramsMap.put("resourceMap", resourceCheckParams);
        }
        NoHttpUtils.httpPost(ContractConstant.PLANNING_SAVE_MODULES, paramsMap, new NoHttpUtils.OnResponseListener() {
            @Override
            public void onSucceed(CommonClass commonClass, int i) {
                dismissProgressDialog();
                if (commonClass != null && commonClass.getData() != null && commonClass.getCode().equals("0")) {
                    SaveModulesBean.DataBean saveModulesBean = JSON.parseObject(commonClass.getData().toString(), SaveModulesBean.DataBean.class);
                    mCardTv.setText(saveModulesBean.getCardCount() + "张卡片");
                    DialogTools.getInstance().showCustomWarning(mActivity, "规划业务完成", "恭喜您获得" + saveModulesBean.getCardCount() + "张卡片", true, new DialogTools.ConfirmListener() {
                        @Override
                        public void setConfirmListener(Dialog dialog, View view, String s) {
                            dialog.dismiss();
                            EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));

                        }
                    });
                } else {
                    ToastUtils.showToast(commonClass.getMsg());
                }
            }

            @Override
            public void onFailed(String s, int i) {
                dismissProgressDialog();

            }

            @Override
            public void onFinish(int i) {
                dismissProgressDialog();
                if (isShow) {
                    ((BaseCardDeskActivity) mActivity).hideTitleBt();
                }
                isShow = !isShow;
            }
        } , 0);
	    }
    }

    //初始化控件
    private void initView(View view) {
        EventBus.getDefault().register(this);
        mIndusLayout = (LinearLayout) view.findViewById(R.id.indus_layout);
        mResourceFactorShipLayout = (LinearLayout) view.findViewById(R.id.resource_factor_ship_layout);
        mClientLv = (MyListView) view.findViewById(R.id.client_lv);
	    mCardTv = (TextView) view.findViewById(R.id.card_tv);
	    mIndustryTv = (TextView) view.findViewById(R.id.indus_tv);
        mResourceLv = (MyListView) view.findViewById(R.id.resource_lv);
        mResourceFactorLv = (MyListView) view.findViewById(R.id.resource_factor_lv);
        mStateLayout = (StateLayout) view.findViewById(R.id.sl_state);
        mSupplierLv = (MyListView) view.findViewById(R.id.supplier_lv);
        mResourceShipIv = (ImageView) view.findViewById(R.id.resource_ship_iv);
        mResourceShipTv = (TextView) view.findViewById(R.id.resource_ship_tv);
        mResourceFactorShipIv = (ImageView) view.findViewById(R.id.resource_factor_iv);
        mResourceFactorShipTv = (TextView) view.findViewById(R.id.resource_factor_tv);
        mResourceShipLayout = (LinearLayout) view.findViewById(R.id.resource_ship_layout);
        mElasticScrollView = (ElasticScrollView) view.findViewById(R.id.ecl_custom);
        mElasticScrollView.setVisibility(View.INVISIBLE);
        mElasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                if (!isShow) {
                    ((BaseCardDeskActivity) mActivity).downPull_3();
                    ((BaseCardDeskActivity) mActivity).showTitleBt1();
                    ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);

                } else {
                    ((BaseCardDeskActivity) mActivity).hideTitleBt();
                }
                isShow = !isShow;

            }

            @Override
            public void onUpPull() {

            }
        });
        ((BaseCardDeskActivity) mActivity).setTitleBt1Text("确定");
        mResourceShipLayout.setOnClickListener(this);
        mResourceFactorShipLayout.setOnClickListener(this);
        mResourceShipLayout.setEnabled(false);
        mResourceFactorShipLayout.setEnabled(false);
        mResourceShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
        mResourceFactorShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));

    }


    //点击事件
    private void initEvent() {
        mIndusLayout.setOnClickListener(this);
        mClientLv.setOnItemClickListener(this);
        mResourceLv.setOnItemClickListener(this);
        mResourceFactorLv.setOnItemClickListener(this);
        mSupplierLv.setOnItemClickListener(this);
    }

    @Override
    public void requestDatas() {
        mStateLayout.showProgressView(true);
        Map<String, Object> map = new HashMap<>();
        if (mBusId != null) {
            map.put("buId", mBusId);
        }
        NoHttpUtils.httpPost(ContractConstant.PLANNING_GET_BUSINESS_MODULES, map, new NoHttpUtils.OnResponseListener() {
            @Override
            public void onSucceed(CommonClass commonClass, int i) {

                if (commonClass != null && commonClass.getData() != null) {
                    mElasticScrollView.setVisibility(View.VISIBLE);
                    mStateLayout.showContentView();
                    TestBean.DataBean businessModuleBean = JSON.parseObject(commonClass.getData().toString(), TestBean.DataBean.class);

                    if (businessModuleBean != null) {
                        mCardTv.setText(businessModuleBean.getCardCount() + "张卡片");
                    }

                    /**
                     * 客户
                     */
                    if (businessModuleBean != null && businessModuleBean.getCUSTOMER() != null) {
                        for (int j = 0; j < businessModuleBean.getCUSTOMER().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getCUSTOMER().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getCUSTOMER().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getCUSTOMER().get(j).getImageUrl().getSelectedUrl());
                            beanList.setName(businessModuleBean.getCUSTOMER().get(j).getName());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            if (!TextUtils.isEmpty(businessModuleBean.getCUSTOMER().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getCUSTOMER().get(j).getValue()));
                            }
                            mCustomerCheckedList.add(beanList);
                        }

                        if (mCustomerCheckedList.size() > 0 && mResourceCheckedList.size() > 0) {
                            mResourceShipLayout.setEnabled(true);
                            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship_white));
                            mResourceShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.rescource_background));
                        } else {
                            mResourceShipLayout.setEnabled(false);
                            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
                            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship));
                            mResourceShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                        }

                        if (mCustomerCheckedList.size() > 0) {
                            List<Double> list = new ArrayList<>();
                            for (int k = 0; k < mCustomerCheckedList.size(); k++) {
                                list.add((double) mCustomerCheckedList.get(k).getProgress());
                            }
                            List<Double> newList =  ArithMetic.getPinRatio(ArithMetic.getPinRatio(ArithMetic.getPinRatio(list, 12d), 12d) , 12d);
                            if (newList != null && newList.size() > 0 && mCustomerCheckedList.size() == newList.size()) {
                                for (int l = 0; l < newList.size(); l++) {
                                    mCustomerCheckedList.get(l).setScale(newList.get(l));
                                }
                            }
                        }
                        if (mCustomerCheckedList.size() > 0) {
                            mClientPinCardBeanList = mCustomerCheckedList;
                            mClientAdapter = new PinCardAdapter(mCustomerCheckedList, mActivity, mLvHeight, R.layout.client_pincard_item);
                            mClientLv.setAdapter(mClientAdapter);
                        }
                    }

                    /**
                     * 资源
                     */
                    if (businessModuleBean != null && businessModuleBean.getRESOURCE() != null) {
                        for (int j = 0; j < businessModuleBean.getRESOURCE().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getRESOURCE().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getRESOURCE().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getRESOURCE().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            beanList.setName(businessModuleBean.getRESOURCE().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getRESOURCE().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getRESOURCE().get(j).getValue()));
                            }
                            mResourceCheckedList.add(beanList);
                        }
                        if (mResourceCheckedList.size() > 0) {
                            mResourcePinCardBeanList = mResourceCheckedList;
                            mResourceAdapter = new PinCardAdapter(mResourceCheckedList, mActivity, mLvHeight, R.layout.rescource_pincard_item);
                            mResourceLv.setAdapter(mResourceAdapter);
                        }
                        if (mCustomerCheckedList.size() > 0 && mResourceCheckedList.size() > 0) {
                            mResourceShipLayout.setEnabled(true);
                            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship_white));
                            mResourceShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.rescource_background));
                        } else {
                            mResourceShipLayout.setEnabled(false);
                            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
                            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship));
                            mResourceShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                        }
                    }


                    /**
                     * 拥有的资源要素
                     */
                    if (businessModuleBean != null && businessModuleBean.getHAVE_RESOURCE_FACTORS() != null) {
                        for (int j = 0; j < businessModuleBean.getHAVE_RESOURCE_FACTORS().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            beanList.setName(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getHAVE_RESOURCE_FACTORS().get(j).getValue()));
                            }
                            mHaveResourceFactorCheckedList.add(beanList);
                        }

                    }


                    /**
                     * 从服务端返回的资源关系
                     */
                    if (businessModuleBean != null && businessModuleBean.getCUSTOMER_AND_RESOURCE() != null) {
                        for (int j = 0; j < businessModuleBean.getCUSTOMER_AND_RESOURCE().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setName(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getValue())) {
                                beanList.setValue(businessModuleBean.getCUSTOMER_AND_RESOURCE().get(j).getValue());
                            }
                            mCustomersAndResourceListFromNet.add(beanList);
                        }

                    }

                    /**
                     * 从服务端返回的资源要素关系
                     */
                    if (businessModuleBean != null && businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS() != null) {
                        for (int j = 0; j < businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setName(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getValue())) {
                                beanList.setValue(businessModuleBean.getPROVIDER_AND_RESOURCE_FACTORS().get(j).getValue());
                            }
                            mResourceFactorAndSupplyListFromNet.add(beanList);
                        }

                    }

                    /**
                     * 行业
                     */
                    if (businessModuleBean != null && businessModuleBean.getINDUSTRY() != null) {
                        for (int j = 0; j < businessModuleBean.getINDUSTRY().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getINDUSTRY().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getINDUSTRY().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getINDUSTRY().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            beanList.setName(businessModuleBean.getINDUSTRY().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getINDUSTRY().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getINDUSTRY().get(j).getValue()));
                            }
                            mDefaultIndustryCheckedList.add(beanList);
                        }
                        if (mDefaultIndustryCheckedList.size() == 1) {
                            mIndustryTv.setText(mDefaultIndustryCheckedList.get(0).getName());
                        } else if (mDefaultIndustryCheckedList.size() >= 2) {
                            mIndustryTv.setText(mDefaultIndustryCheckedList.size() + "个行业");
                        }
                    }


                    /**
                     * 需要的资源要素
                     */
                    if (businessModuleBean != null && businessModuleBean.getNEED_RESOURCE_FACTORS() != null) {
                        for (int j = 0; j < businessModuleBean.getNEED_RESOURCE_FACTORS().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            beanList.setName(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getNEED_RESOURCE_FACTORS().get(j).getValue()));
                            }
                            mNeedResourceFactorCheckedList.add(beanList);
                        }

                    }


                    /**
                     * 供应商
                     */
                    if (businessModuleBean != null && businessModuleBean.getPROVIDER() != null) {
                        for (int j = 0; j < businessModuleBean.getPROVIDER().size(); j++) {
                            ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                            beanList.setCode(businessModuleBean.getPROVIDER().get(j).getCode());
                            ChooseModuleBean.ModuleList.BeanList.ImageUrl imageUrl = new ChooseModuleBean.ModuleList.BeanList.ImageUrl();
                            imageUrl.setDefaultUrl(businessModuleBean.getPROVIDER().get(j).getImageUrl().getDefaultUrl());
                            imageUrl.setSelectedUrl(businessModuleBean.getPROVIDER().get(j).getImageUrl().getSelectedUrl());
                            beanList.setImageUrl(imageUrl);
                            beanList.setSelect(true);
                            beanList.setName(businessModuleBean.getPROVIDER().get(j).getName());
                            if (!TextUtils.isEmpty(businessModuleBean.getPROVIDER().get(j).getValue())) {
                                beanList.setProgress(Integer.parseInt(businessModuleBean.getPROVIDER().get(j).getValue()));
                            }
                            mSupplierCheckedList.add(beanList);
                        }

                        if (mHaveResourceFactorCheckedList.size() > 0 && mNeedResourceFactorCheckedList.size() > 0 && mSupplierCheckedList.size() > 0) {
                            mResourceFactorShipLayout.setEnabled(true);
                            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation_white));
                            mResourceFactorShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.supplier_background));
                        } else {
                            mResourceFactorShipLayout.setEnabled(false);
                            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
                            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation));
                            mResourceFactorShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                        }

                        if (mSupplierCheckedList.size() > 0) {
                            List<Double> list = new ArrayList<>();
                            for (int k = 0; k < mSupplierCheckedList.size(); k++) {
                                list.add((double) mSupplierCheckedList.get(k).getProgress());
                            }
                            List<Double> newList =  ArithMetic.getPinRatio(ArithMetic.getPinRatio(ArithMetic.getPinRatio(list, 12d), 12d) , 12d);
                            if (newList != null && newList.size() > 0 && mSupplierCheckedList.size() == newList.size()) {
                                for (int l = 0; l < newList.size(); l++) {
                                    mSupplierCheckedList.get(l).setScale(newList.get(l));
                                }
                            }
                        }
                        if (mSupplierCheckedList.size() > 0) {
                            mSupplierPinCardBeanList = mSupplierCheckedList;
                            mClientAdapter = new PinCardAdapter(mSupplierCheckedList, mActivity, mLvHeight, R.layout.supplier_pincard_item);
                            mSupplierLv.setAdapter(mClientAdapter);
                        }
                    }
                    int haveResFactorShowCount = 0;

                    //开始整理数据
                    final List<ChooseModuleBean.ModuleList.BeanList> mShowCheckedList = new ArrayList<>();
                    //判断需要的资源要素数据有几个，如果大于两个只取2个
                    if (mNeedResourceFactorCheckedList.size() >= 3) {
                        haveResFactorShowCount = 3;
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(1));
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(2));
                    } else if (mNeedResourceFactorCheckedList.size() == 1) {
                        //不应该存在0个所以直接添加第一个
                        haveResFactorShowCount = 1;
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
                    } else if (mNeedResourceFactorCheckedList.size() == 2) {
                        haveResFactorShowCount = 2;
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
                        mShowCheckedList.add(mNeedResourceFactorCheckedList.get(1));
                    }
                    //需要的资源要素
                    if (mHaveResourceFactorCheckedList.size() > 0) {
                        mShowCheckedList.addAll(mHaveResourceFactorCheckedList);
                    }
                    if (mShowCheckedList.size() > 0) {
                        mResourceFactorPinCardBeanList = mShowCheckedList;
                        mResourceAdapter = new PinCardAdapter(mResourceFactorPinCardBeanList, mActivity, mLvHeight, R.layout.rescource_factort_pincard_item, haveResFactorShowCount);
                        mResourceFactorLv.setAdapter(mResourceAdapter);
                    }

                    if (mHaveResourceFactorCheckedList.size() > 0 && mNeedResourceFactorCheckedList.size() > 0 && mSupplierCheckedList.size() > 0) {
                        mResourceFactorShipLayout.setEnabled(true);
                        mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                        mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation_white));
                        mResourceFactorShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.supplier_background));
                    } else {
                        mResourceFactorShipLayout.setEnabled(false);
                        mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
                        mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation));
                        mResourceFactorShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                    }


                    /**
                     * 开始整理资源关系第一次获得的数据
                     */
                    List<CustomerAndResListBean> list = new ArrayList<>();
                    for (int l = 0; l < mResourceCheckedList.size(); l++) {
                        CustomerAndResListBean customerAndResBean = new CustomerAndResListBean();
                        customerAndResBean.setName(mResourceCheckedList.get(l).getName());
                        customerAndResBean.setCode(mResourceCheckedList.get(l).getCode());
                        customerAndResBean.setUrl(mResourceCheckedList.get(l).getImageUrl().getSelectedUrl());
                        List<CustomerAndResListBean.Customers> customerses = new ArrayList<>();
                        for (int m = 0; m < mCustomerCheckedList.size(); m++) {
                            CustomerAndResListBean.Customers customers = new CustomerAndResListBean.Customers();
                            for (int k = 0; k < mCustomersAndResourceListFromNet.size(); k++) {
                                if (mResourceCheckedList.get(l).getName().equals(mCustomersAndResourceListFromNet.get(k).getName())) {
                                    if (!TextUtils.isEmpty(mCustomersAndResourceListFromNet.get(k).getValue())) {
                                        String code = mCustomersAndResourceListFromNet.get(k).getValue();
                                        List<String> result = Arrays.asList(code.split(","));
                                        if (result.contains(mCustomerCheckedList.get(m).getCode())) {
                                            customers.setSelected(true);
                                        } else {
                                            customers.setSelected(false);

                                        }
                                    }

                                }
                            }
                            customers.setCode(mCustomerCheckedList.get(m).getCode());
                            customers.setName(mCustomerCheckedList.get(m).getName());
//                    customers.setSelected(mCustomerCheckedList.get(j).isSelect());
                            customerses.add(customers);
                        }
                        customerAndResBean.setList(customerses);
                        list.add(customerAndResBean);
                    }
                    //组合好的新数据list 所有要用到的数据塞到fragment中
                    CustomerAndResBean customerAndResBean = new CustomerAndResBean();
                    customerAndResBean.setListBeen(list);
                    if (mCustomerAndResBean == null) {
                        CustomerAndResBean customerAndResBean1 = new CustomerAndResBean();
                        customerAndResBean1.setListBeen(list);
                        mCustomerAndResBean = customerAndResBean1;
                    }

                    /**
                     * 开始整理资源要素关系
                     */
                    for (int p = 0; p < mSupplierCheckedList.size(); p++) {
                        CustomerAndResListBean supplyAndResFactorBean = new CustomerAndResListBean();
                        supplyAndResFactorBean.setName(mSupplierCheckedList.get(p).getName());
                        supplyAndResFactorBean.setCode(mSupplierCheckedList.get(p).getCode());
                        supplyAndResFactorBean.setUrl(mSupplierCheckedList.get(p).getImageUrl().getDefaultUrl());

                        List<CustomerAndResListBean.Customers> needRecources = new ArrayList<>();
                        for (int j = 0; j < mNeedResourceFactorCheckedList.size(); j++) {
                            CustomerAndResListBean.Customers customers = new CustomerAndResListBean.Customers();
                            //过滤数据
                            for (int k = 0; k < mResourceFactorAndSupplyListFromNet.size(); k++) {
                                if (mSupplierCheckedList.get(p).getName().equals(mResourceFactorAndSupplyListFromNet.get(k).getName())) {
                                    if (!TextUtils.isEmpty(mResourceFactorAndSupplyListFromNet.get(k).getValue())) {
                                        String code = mResourceFactorAndSupplyListFromNet.get(k).getValue();
                                        List<String> result = Arrays.asList(code.split(","));
                                        if (result.contains(mNeedResourceFactorCheckedList.get(j).getCode())) {
                                            customers.setSelected(true);
                                        } else {
                                            customers.setSelected(false);

                                        }
                                    }

                                }
                            }

                            customers.setCode(mNeedResourceFactorCheckedList.get(j).getCode());
                            customers.setName(mNeedResourceFactorCheckedList.get(j).getName());
                            customers.setDefaultUrl(mNeedResourceFactorCheckedList.get(j).getImageUrl().getDefaultUrl());
                            customers.setSelectUrl(mNeedResourceFactorCheckedList.get(j).getImageUrl().getSelectedUrl());
//                    customers.setSelected(mNeedResourceFactorCheckedList.get(j).isRelevance());
                            needRecources.add(customers);
                        }
                        supplyAndResFactorBean.setList(needRecources);
                        list.add(supplyAndResFactorBean);
                    }
                    //组合好的新数据list 所有要用到的数据塞到fragment中
                    CustomerAndResBean customerAndResBean1 = new CustomerAndResBean();
                    customerAndResBean1.setListBeen(list);


                    if (mRecourseFactorShipBean == null) {
                        mRecourseFactorShipBean = customerAndResBean1;
                    }





                    mClientLv.post(new Runnable() {
                        @Override
                        public void run() {
                            mLvHeight = mClientLv.getHeight();
                            if (mCustomerCheckedList.size() > 0) {
                                mClientAdapter = new PinCardAdapter(mCustomerCheckedList, mActivity, mLvHeight, R.layout.client_pincard_item);
                                mClientLv.setAdapter(mClientAdapter);
                            } else {
                                ChooseModuleBean.ModuleList.BeanList beanList = new ChooseModuleBean.ModuleList.BeanList();
                                beanList.setName("客户类型");
                                beanList.setProgress(100);
                                beanList.setShowPercent(false);
                                mClientPinCardBeanList.add(beanList);
                                mClientAdapter = new PinCardAdapter(mClientPinCardBeanList, mActivity, mLvHeight, R.layout.client_pincard_item);
                                mClientLv.setAdapter(mClientAdapter);
                            }

                            if (mResourceCheckedList.size() > 0) {
                                mResourceAdapter = new PinCardAdapter(mResourceCheckedList, mActivity, mLvHeight, R.layout.rescource_pincard_item);
                                mResourceLv.setAdapter(mResourceAdapter);
                            } else {
                                ChooseModuleBean.ModuleList.BeanList beanList1 = new ChooseModuleBean.ModuleList.BeanList();
                                beanList1.setName("提供的服务");
                                beanList1.setProgress(1);
                                mResourcePinCardBeanList.add(beanList1);
                                mResourceAdapter = new PinCardAdapter(mResourcePinCardBeanList, mActivity, mLvHeight, R.layout.rescource_pincard_item);
                                mResourceLv.setAdapter(mResourceAdapter);
                            }

                            if (mShowCheckedList.size() > 0) {
                                mResourceFactorAdapter = new PinCardAdapter(mShowCheckedList, mActivity, mLvHeight, R.layout.rescource_factort_pincard_item);
                                mResourceFactorLv.setAdapter(mResourceFactorAdapter);
                            } else {
                                ChooseModuleBean.ModuleList.BeanList beanList2 = new ChooseModuleBean.ModuleList.BeanList();
                                beanList2.setName("需要采购和拥有的资源");
                                beanList2.setProgress(1);
                                mResourceFactorPinCardBeanList.add(beanList2);
                                mResourceFactorAdapter = new PinCardAdapter(mResourceFactorPinCardBeanList, mActivity, mLvHeight, R.layout.rescource_factort_pincard_item);
                                mResourceFactorLv.setAdapter(mResourceFactorAdapter);
                            }

                            if (mSupplierCheckedList.size() > 0) {
                                mSupplierAdapter = new PinCardAdapter(mSupplierCheckedList, mActivity, mLvHeight, R.layout.supplier_pincard_item);
                                mSupplierLv.setAdapter(mSupplierAdapter);
                            } else {
                                ChooseModuleBean.ModuleList.BeanList beanList3 = new ChooseModuleBean.ModuleList.BeanList();
                                beanList3.setName("供应商类型");
                                beanList3.setShowPercent(false);
                                beanList3.setProgress(100);
                                mSupplierPinCardBeanList.add(beanList3);
                                mSupplierAdapter = new PinCardAdapter(mSupplierPinCardBeanList, mActivity, mLvHeight, R.layout.supplier_pincard_item);
                                mSupplierLv.setAdapter(mSupplierAdapter);
                            }
                        }
                    });

                } else {
                    mStateLayout.showSystemView(commonClass.getMsg()  , true);
                    mStateLayout.setSystemListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            requestDatas();
                        }
                    });
                    mElasticScrollView.setVisibility(View.INVISIBLE);

                }
                checkCanclick();
            }

            @Override
            public void onFailed(String s, int i) {
                mStateLayout.showSystemView(s , true);
                mStateLayout.setSystemListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        requestDatas();
                    }
                });

            }

            @Override
            public void onFinish(int i) {

            }
        } , 0);


    }

    @Override
    public void onClick(View v) {
        if (isShow) {
            ((BaseCardDeskActivity) mActivity).hideTitleBt();
        }
        isShow = !isShow;
        int clickId = v.getId();
        //顶部行业点击事件
        if (clickId == R.id.indus_layout) {
            //上一次点击过存下来的带过去 ，没有就直接过去
            if (mIndustryCheckedList.size() > 0) {
                Bundle bundle = new Bundle();
                bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA, (Serializable) mIndustryCheckedList);
                if (mBusId != null) {
                    bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID, mBusId);
                }

                SelectIndustryViewPagerFragment selectIndustryViewPagerFragment = new SelectIndustryViewPagerFragment();
                selectIndustryViewPagerFragment.setArguments(bundle);
                pushFragment(selectIndustryViewPagerFragment);
            } else {
                Bundle bundle = new Bundle();
                bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
                if (mBusId != null) {
                    bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID, mBusId);
                }

                SelectIndustryViewPagerFragment selectIndustryViewPagerFragment = new SelectIndustryViewPagerFragment();
                selectIndustryViewPagerFragment.setArguments(bundle);
                pushFragment(selectIndustryViewPagerFragment);
            }
            //资源关系点击
        } else if (clickId == R.id.resource_ship_layout) {
            List<CustomerAndResListBean> list = new ArrayList<>();
            for (int i = 0; i < mResourceCheckedList.size(); i++) {
                CustomerAndResListBean customerAndResBean = new CustomerAndResListBean();
                customerAndResBean.setName(mResourceCheckedList.get(i).getName());
                customerAndResBean.setCode(mResourceCheckedList.get(i).getCode());
                customerAndResBean.setUrl(mResourceCheckedList.get(i).getImageUrl().getSelectedUrl());
                List<CustomerAndResListBean.Customers> customerses = new ArrayList<>();
                for (int j = 0; j < mCustomerCheckedList.size(); j++) {
                    CustomerAndResListBean.Customers customers = new CustomerAndResListBean.Customers();
                    for (int k = 0; k < mCustomersAndResourceListFromNet.size(); k++) {
                        if (mResourceCheckedList.get(i).getName().equals(mCustomersAndResourceListFromNet.get(k).getName())) {
                            if (!TextUtils.isEmpty(mCustomersAndResourceListFromNet.get(k).getValue())) {
                                String code = mCustomersAndResourceListFromNet.get(k).getValue();
                                List<String> result = Arrays.asList(code.split(","));
                                if (result.contains(mCustomerCheckedList.get(j).getCode())) {
                                    customers.setSelected(true);
                                } else {
                                    customers.setSelected(false);

                                }
                            }

                        }
                    }
                    customers.setCode(mCustomerCheckedList.get(j).getCode());
                    customers.setName(mCustomerCheckedList.get(j).getName());
//                    customers.setSelected(mCustomerCheckedList.get(j).isSelect());
                    customerses.add(customers);
                }
                customerAndResBean.setList(customerses);
                list.add(customerAndResBean);
            }
            //组合好的新数据list 所有要用到的数据塞到fragment中
            CustomerAndResBean customerAndResBean = new CustomerAndResBean();
            customerAndResBean.setListBeen(list);
            Bundle bundle = new Bundle();
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_VIEW_PAGER_DATA , customerAndResBean);
            if (mCustomerAndResBean == null) {
                CustomerAndResBean customerAndResBean1 = new CustomerAndResBean();
                customerAndResBean1.setListBeen(list);
                mCustomerAndResBean = customerAndResBean1;
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_LAST_RESCOURCE_SHIP_CHECKED ,mCustomerAndResBean);
            }
            if (mCustomerAndResBean != null) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_LAST_RESCOURCE_SHIP_CHECKED ,mCustomerAndResBean);
            }
            ResourceShipViewPagerFragment resourceShipViewPagerFragment = new ResourceShipViewPagerFragment();
            resourceShipViewPagerFragment.setArguments(bundle);
            pushFragment(resourceShipViewPagerFragment);
        } else if (clickId == R.id.resource_factor_ship_layout) {
/**
 *   资源要素关系点击事件
 */

            List<CustomerAndResListBean> list = new ArrayList<>();
            for (int i = 0; i < mSupplierCheckedList.size(); i++) {
                CustomerAndResListBean supplyAndResFactorBean = new CustomerAndResListBean();
                supplyAndResFactorBean.setName(mSupplierCheckedList.get(i).getName());
                supplyAndResFactorBean.setCode(mSupplierCheckedList.get(i).getCode());
                supplyAndResFactorBean.setUrl(mSupplierCheckedList.get(i).getImageUrl().getDefaultUrl());

                List<CustomerAndResListBean.Customers> needRecources = new ArrayList<>();
                for (int j = 0; j < mNeedResourceFactorCheckedList.size(); j++) {
                    CustomerAndResListBean.Customers customers = new CustomerAndResListBean.Customers();
                    //过滤数据
                    for (int k = 0; k < mResourceFactorAndSupplyListFromNet.size(); k++) {
                        if (mSupplierCheckedList.get(i).getName().equals(mResourceFactorAndSupplyListFromNet.get(k).getName())) {
                            if (!TextUtils.isEmpty(mResourceFactorAndSupplyListFromNet.get(k).getValue())) {
                                String code = mResourceFactorAndSupplyListFromNet.get(k).getValue();
                                List<String> result = Arrays.asList(code.split(","));
                                if (result.contains(mNeedResourceFactorCheckedList.get(j).getCode())) {
                                    customers.setSelected(true);
                                } else {
                                    customers.setSelected(false);

                                }
                            }

                        }
                    }

                    customers.setCode(mNeedResourceFactorCheckedList.get(j).getCode());
                    customers.setName(mNeedResourceFactorCheckedList.get(j).getName());
                    customers.setDefaultUrl(mNeedResourceFactorCheckedList.get(j).getImageUrl().getDefaultUrl());
                    customers.setSelectUrl(mNeedResourceFactorCheckedList.get(j).getImageUrl().getSelectedUrl());
//                    customers.setSelected(mNeedResourceFactorCheckedList.get(j).isRelevance());
                    needRecources.add(customers);
                }
                supplyAndResFactorBean.setList(needRecources);
                list.add(supplyAndResFactorBean);
            }
            //组合好的新数据list 所有要用到的数据塞到fragment中
            CustomerAndResBean customerAndResBean = new CustomerAndResBean();
            customerAndResBean.setListBeen(list);
            Bundle bundle = new Bundle();
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_VIEW_PAGER_DATA , customerAndResBean);


            if (mRecourseFactorShipBean == null) {
                CustomerAndResBean customerAndResBean1 = new CustomerAndResBean();
                customerAndResBean1.setListBeen(list);
                mRecourseFactorShipBean = customerAndResBean1;
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_LAST_RESCOURCE_FACTOR_SHIP_CHECKED ,mRecourseFactorShipBean);
            }
            if (mRecourseFactorShipBean != null) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_LAST_RESCOURCE_FACTOR_SHIP_CHECKED ,mRecourseFactorShipBean);
            }
            ResourceFactorShipViewPagerFragment resourceShipViewPagerFragment = new ResourceFactorShipViewPagerFragment();
            resourceShipViewPagerFragment.setArguments(bundle);
            pushFragment(resourceShipViewPagerFragment);
        }

    }

    /**
     * ('CUSTOMER', '选择客户');
     ('CUSTOMER_AND_RESOURCE', '关联客户和资源');
     ('HAVE_RESOURCE_FACTORS', '拥有的资源要素');
     ('INDUSTRY', '选择行业');
     ('NEED_RESOURCE_FACTORS', '需要的资源要素');
     ('PROVIDER', '选择供应商');
     ('PROVIDER_AND_RESOURCE_FACTORS', '关联供应商和资源要素');
     ('RESOURCE', '提供的资源');

     */

    /**
     * 每个竖直listview的点击事件
     *
     * @param parent
     * @param view
     * @param position
     * @param id
     */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (isShow) {
            ((BaseCardDeskActivity) mActivity).hideTitleBt();
        }
        isShow = !isShow;
        int clickId = parent.getId();
        //客户
        if (clickId == R.id.client_lv) {
            Bundle bundle = new Bundle();
            List<SourceListBean> mSourceListBeen = getSourceList("CUSTOMER");
            if (mCustomerCheckedList.size() > 0) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA, (Serializable) mCustomerCheckedList);
            }
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_SERVIC_CLIENTS_DATA, (Serializable) mSourceListBeen);
            if (mBusId != null) {
                bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID , mBusId);
            }
            bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION, true);
            ManySeekBarFragment manySeekBarFragment = new ManySeekBarFragment();
            manySeekBarFragment.setArguments(bundle);
            pushFragment(manySeekBarFragment);
            //资源
        } else if (clickId == R.id.resource_lv) {
            ModuleQueryRequest moduleQueryRequest = new ModuleQueryRequest();
            List<SourceListBean> sourceList = getSourceList("RESOURCE");
            moduleQueryRequest.setSourceList(sourceList);
            ModuleQueryRequest.BaseQuery baseQuery = new ModuleQueryRequest.BaseQuery();
            baseQuery.setPage(1);
            baseQuery.setSize(10000);
            moduleQueryRequest.setBaseQuery(baseQuery);
            moduleQueryRequest.setSourceModule("RESOURCE");
            moduleQueryRequest.setTaskType("function");
            if (mBusId != null) {
                moduleQueryRequest.setBuId(mBusId);
            }

            if (mResourceCheckedList.size() > 0) {
                Bundle bundle = new Bundle();
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA, (Serializable) mResourceCheckedList);
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_QUARY_PARAMS, moduleQueryRequest);
                bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
                if (mBusId != null) {
                    bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID, mBusId);
                }
                SupplyOfResourceViewPagerFragment supplyOfResourcesViewPagerFragment = new SupplyOfResourceViewPagerFragment();
                supplyOfResourcesViewPagerFragment.setArguments(bundle);
                pushFragment(supplyOfResourcesViewPagerFragment);
            } else {
                Bundle bundle = new Bundle();
                bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_QUARY_PARAMS, (Serializable) moduleQueryRequest);
                if (mBusId != null) {
                    bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID, mBusId);
                }
                SupplyOfResourceViewPagerFragment supplyOfResourcesViewPagerFragment = new SupplyOfResourceViewPagerFragment();
                supplyOfResourcesViewPagerFragment.setArguments(bundle);
                pushFragment(supplyOfResourcesViewPagerFragment);
            }

            //资源要素
        } else if (clickId == R.id.resource_factor_lv) {
            ModuleQueryRequest mHaveModuleQueryRequest = getResourceFactorParams("HAVE_RESOURCE_FACTORS");

            ModuleQueryRequest mNeedModuleQueryRequest = getResourceFactorParams("NEED_RESOURCE_FACTORS");

            if (mBusId != null) {
                mHaveModuleQueryRequest.setBuId(mBusId);
                mNeedModuleQueryRequest.setBuId(mBusId);
            }
            Bundle bundle = new Bundle();
            if (mHaveResourceFactorCheckedList != null && mHaveResourceFactorCheckedList.size() > 0) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_HAVE_RESOURCE_CHECKED_DATA, (Serializable) mHaveResourceFactorCheckedList);
            }
            if (mNeedResourceFactorCheckedList != null && mNeedResourceFactorCheckedList.size() > 0) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_NEED_RESOURCE_CHECKED_DATA, (Serializable) mNeedResourceFactorCheckedList);
            }
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_NEED_RESOURCE_PARAMS, mNeedModuleQueryRequest);
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_HAVE_RESOURCE_PARAMS, mHaveModuleQueryRequest);
            bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
            ResourceFactorMainFragment resourceFactorMainFragment = new ResourceFactorMainFragment();
            resourceFactorMainFragment.setArguments(bundle);
            pushFragment(resourceFactorMainFragment);


        } else if (clickId == R.id.supplier_lv) {
            Bundle bundle = new Bundle();
            List<SourceListBean> mSourceListBeen = getSourceList("PROVIDER");
            if (mSupplierCheckedList.size() > 0) {
                bundle.putSerializable(ContractConstant.KEY_BUNDLE_CHECKED_DATA, (Serializable) mSupplierCheckedList);
            }
            bundle.putSerializable(ContractConstant.KEY_BUNDLE_SUPPLY_PARAMS, (Serializable) mSourceListBeen);
            bundle.putBoolean(ContractConstant.KEY_IS_FUNCTION , true);
            if (mBusId != null) {
                bundle.putString(ContractConstant.KEY_BUNDLE_CONTRACT_BUID , mBusId);
            }
            SupplySeekBarFragment manySeekBarFragment = new SupplySeekBarFragment();
            manySeekBarFragment.setArguments(bundle);
            pushFragment(manySeekBarFragment);

        }




    }

    @NonNull
    private ModuleQueryRequest getResourceFactorParams(String type) {
        ModuleQueryRequest moduleQueryRequest = new ModuleQueryRequest();
        List<SourceListBean> sourceList = getSourceList(type);
        moduleQueryRequest.setSourceList(sourceList);
        ModuleQueryRequest.BaseQuery baseQuery = new ModuleQueryRequest.BaseQuery();
        baseQuery.setPage(1);
        baseQuery.setSize(10000);
        moduleQueryRequest.setBaseQuery(baseQuery);
        moduleQueryRequest.setSourceModule(type);
        moduleQueryRequest.setTaskType("function");
        return moduleQueryRequest;
    }

    /**
     * 点击行业返回的数据
     *
     * @param checkIndusEvent
     */
    public void onEventMainThread(CheckIndusEvent checkIndusEvent) {
        isEdited = true;
        if (checkIndusEvent.getIndustryChecks().size() == 1) {
            mIndustryTv.setText(checkIndusEvent.getIndustryChecks().get(0).getName());
        } else if (checkIndusEvent.getIndustryChecks().size() >= 2) {
            mIndustryTv.setText(checkIndusEvent.getIndustryChecks().size() + "个行业");
        }
        mIndustryCheckedList = checkIndusEvent.getIndustryChecks();
        checkCanclick();

    }

    /**
     * 点击资源返回的数据
     *
     * @param checkIndusEvent
     */
    public void onEventMainThread(CheckResEvent checkIndusEvent) {
        isEdited = true;
        mResourceCheckedList = checkIndusEvent.getIndustryChecks();
        if (mResourceCheckedList.size() > 0) {
            mResourcePinCardBeanList = mResourceCheckedList;
            mResourceAdapter = new PinCardAdapter(mResourceCheckedList, mActivity, mLvHeight, R.layout.rescource_pincard_item);
            mResourceLv.setAdapter(mResourceAdapter);
        }
        if (mCustomerCheckedList.size() > 0 && mResourceCheckedList.size() > 0) {
            mResourceShipLayout.setEnabled(true);
            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship_white));
            mResourceShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.rescource_background));
        } else {
            mResourceShipLayout.setEnabled(false);
            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship));
            mResourceShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
        }
        checkCanclick();

    }

    /**
     * 点击资源要素返回的数据
     *
     * @param checkIndusEvent
     */
    public void onEventMainThread(CheckAllResFactorEvent checkIndusEvent) {
        isEdited = true;
        int haveResFactorShowCount = 0;
        mNeedResourceFactorCheckedList = checkIndusEvent.getmNeedResFactorCheckedList();
        mHaveResourceFactorCheckedList = checkIndusEvent.getmHaveResFactorCheckedList();

        //开始整理数据
        List<ChooseModuleBean.ModuleList.BeanList> mShowCheckedList = new ArrayList<>();
        //判断需要的资源要素数据有几个，如果大于两个只取2个
        if (mNeedResourceFactorCheckedList.size() >= 3) {
            haveResFactorShowCount = 3;
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(1));
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(2));
        } else if (mNeedResourceFactorCheckedList.size() == 1){
            //不应该存在0个所以直接添加第一个
            haveResFactorShowCount = 1;
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
        } else if (mNeedResourceFactorCheckedList.size() == 2) {
            haveResFactorShowCount = 2;
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(0));
            mShowCheckedList.add(mNeedResourceFactorCheckedList.get(1));
        }
        //需要的资源要素
        if (mHaveResourceFactorCheckedList.size() > 0) {
            mShowCheckedList.addAll(mHaveResourceFactorCheckedList);
        }
        if (mShowCheckedList.size() > 0) {
            mResourceFactorPinCardBeanList = mShowCheckedList;
            mResourceAdapter = new PinCardAdapter(mResourceFactorPinCardBeanList, mActivity, mLvHeight, R.layout.rescource_factort_pincard_item , haveResFactorShowCount);
            mResourceFactorLv.setAdapter(mResourceAdapter);
        }

        if (mHaveResourceFactorCheckedList.size() > 0 && mNeedResourceFactorCheckedList.size() > 0 && mSupplierCheckedList.size() > 0) {
            mResourceFactorShipLayout.setEnabled(true);
            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation_white));
            mResourceFactorShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.supplier_background));
        } else {
            mResourceFactorShipLayout.setEnabled(false);
            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation));
            mResourceFactorShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
        }
        checkCanclick();

    }

    /**
     * 点击客户返回的数据
     *
     * @param checkIndusEvent
     */
    public void onEventMainThread(CheckCustomersEvent checkIndusEvent) {
        isEdited = true;
        mCustomerCheckedList = checkIndusEvent.getmCustomerCheckedList();
        if (mCustomerCheckedList.size() > 0) {
            List<Double> list = new ArrayList<>();
            for (int i = 0; i < mCustomerCheckedList.size(); i++) {
                list.add((double) mCustomerCheckedList.get(i).getProgress());
            }
            List<Double> newList =  ArithMetic.getPinRatio(ArithMetic.getPinRatio(ArithMetic.getPinRatio(list, 15d), 15d) , 15d);
            if (newList != null && newList.size() > 0 && mCustomerCheckedList.size() == newList.size()) {
                for (int i = 0; i < newList.size(); i++) {
                    mCustomerCheckedList.get(i).setScale(newList.get(i));
                }
            }
        }
        if (mCustomerCheckedList.size() > 0) {
            mClientPinCardBeanList = mCustomerCheckedList;
            mClientAdapter = new PinCardAdapter(mCustomerCheckedList, mActivity, mLvHeight, R.layout.client_pincard_item);
            mClientLv.setAdapter(mClientAdapter);
        }
        if (mCustomerCheckedList.size() > 0 && mResourceCheckedList.size() > 0) {
            mResourceShipLayout.setEnabled(true);
            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship_white));
            mResourceShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.rescource_background));
        } else {
            mResourceShipLayout.setEnabled(false);
            mResourceShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
            mResourceShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_relationship));
            mResourceShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
        }
        checkCanclick();

    }

    /**
     * 点击供应商返回的数据
     *
     * @param checkIndusEvent
     */
    public void onEventMainThread(CheckSupplyEvent checkIndusEvent) {
        isEdited = true;
        mSupplierCheckedList = checkIndusEvent.getmCustomerCheckedList();
        if (mSupplierCheckedList.size() > 0) {
            List<Double> list = new ArrayList<>();
            for (int i = 0; i < mSupplierCheckedList.size(); i++) {
                list.add((double) mSupplierCheckedList.get(i).getProgress());
            }
            List<Double> newList =  ArithMetic.getPinRatio(ArithMetic.getPinRatio(ArithMetic.getPinRatio(list, 15d), 15d) , 15d);
            if (newList != null && newList.size() > 0 && mSupplierCheckedList.size() == newList.size()) {
                for (int i = 0; i < newList.size(); i++) {
                    mSupplierCheckedList.get(i).setScale(newList.get(i));
                }
            }
        }
        if (mSupplierCheckedList.size() > 0) {
            mSupplierPinCardBeanList = mSupplierCheckedList;
            mClientAdapter = new PinCardAdapter(mSupplierCheckedList, mActivity, mLvHeight, R.layout.supplier_pincard_item);
            mSupplierLv.setAdapter(mClientAdapter);
        }
        if (mHaveResourceFactorCheckedList.size() > 0 && mNeedResourceFactorCheckedList.size() > 0 && mSupplierCheckedList.size() > 0) {
            mResourceFactorShipLayout.setEnabled(true);
            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation_white));
            mResourceFactorShipLayout.setBackground(mActivity.getResources().getDrawable(R.drawable.supplier_background));
        } else {
            mResourceFactorShipLayout.setEnabled(false);
            mResourceFactorShipTv.setTextColor(mActivity.getResources().getColor(R.color.common_color_c7_96999e));
            mResourceFactorShipIv.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.resource_factor_relation));
            mResourceFactorShipLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
        }
        checkCanclick();


    }

    /**
     * 点击资源关系返回的数据
     *
     * @param checkResourceShipEvent
     */
    public void onEventMainThread(CheckResourceShipEvent checkResourceShipEvent) {
        isEdited = true;
        mCustomerAndResBean = checkResourceShipEvent.getCustomerAndResBean();
        checkCanclick();


    }

    /**
     * 点击资源要素关系返回的数据
     *
     * @param checkResourceShipEvent
     */
    public void onEventMainThread(CheckResourceFactorShipEvent checkResourceShipEvent) {
        isEdited = true;
        mRecourseFactorShipBean = checkResourceShipEvent.getCustomerAndResBean();
        checkCanclick();



    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public  String listToString(List<String> stringList){
        if (stringList==null) {
            return null;
        }
        StringBuilder result=new StringBuilder();
        boolean flag=false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            }else {
                flag=true;
            }
            result.append(string);
        }
        return result.toString();
    }

    /**
     *  private List<ChooseModuleBean.ModuleList.BeanList> mIndustryCheckedList = new ArrayList<>(); //行业已选的条目
     private List<ChooseModuleBean.ModuleList.BeanList> mCustomerCheckedList = new ArrayList<>(); //客户已选的条目
     private List<ChooseModuleBean.ModuleList.BeanList> mResourceCheckedList = new ArrayList<>(); //资源已选的条目
     private List<ChooseModuleBean.ModuleList.BeanList> mNeedResourceFactorCheckedList = new ArrayList<>(); //需要的资源要素已选的条目
     private List<ChooseModuleBean.ModuleList.BeanList> mHaveResourceFactorCheckedList = new ArrayList<>(); //拥有的资源要素已选的条目

     private List<ChooseModuleBean.ModuleList.BeanList> mSupplierCheckedList = new ArrayList<>(); //供应商已选的条目
     int mLvHeight;
     CustomerAndResBean mCustomerAndResBean;

     CustomerAndResBean mRecourseFactorShipBean;
     * @return
     */
    private void checkCanclick() {
        if (mIndustryCheckedList.size() > 0 && mCustomerCheckedList.size() > 0 && mResourceCheckedList.size() > 0 && mNeedResourceFactorCheckedList.size() > 0
                && mHaveResourceFactorCheckedList.size() > 0 && mSupplierCheckedList.size() > 0 && mCustomerAndResBean != null && mCustomerAndResBean.getListBeen().size() > 0 && mRecourseFactorShipBean != null
                && mRecourseFactorShipBean.getListBeen().size() > 0) {
        }
    }


    public void onEventMainThread(BackListenerEvent backListenerEvent) {
        if (backListenerEvent.getMsg().equals("isFunctionPinCardMainFragment")) {
            if (isEdited) {
                DialogTools.getInstance().showTCDialog(mActivity, "确认返回", "内容未提交，返回将不会保存，确认返回？", "再看看", "返回", new DialogTools.ConfirmListener() {
                    @Override
                    public void setConfirmListener(Dialog dialog, View view, String s) {
                        dialog.dismiss();

                    }
                }, new DialogTools.DismissListener() {
                    @Override
                    public void setDismissListener(Dialog dialog, View view) {
                        dialog.dismiss();
                        popFragment();
                    }
                });
            }else {
                popFragment();
            }
        }
    }
}
